package org.example.design.factory.itf.impl;

import cn.hutool.json.JSONUtil;
import org.example.design.factory.coupon.CouponResult;
import org.example.design.factory.coupon.CouponService;
import org.example.design.factory.itf.Commodity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @Classname CounponCommdityImpl
 * @Description 优惠券发布实现类
 * @Date 2020/10/30 10:58 上午
 * @Created by xiangjd
 */
public class CounponCommdityService implements Commodity {
    private Logger logger = LoggerFactory.getLogger(CounponCommdityService.class);

    private CouponService couponService = new CouponService();

    @Override
    public void SendCommidIty(String userId, String commId, String bizId, Map<String, String> extMap) throws Exception {
        CouponResult couponResult = couponService.sendCoupon(userId, commId, bizId);
        logger.info("请求参数【优惠券】=====: uid:{},commId:{}, bizId:{},extMap:{}", userId, commId, bizId, JSONUtil.toJsonStr(extMap));
        logger.info("测试结果【优惠券】=====：{}", JSONUtil.toJsonStr(couponResult));
        if (!"0000".equals(couponResult.getCode())) {
            throw new RuntimeException(couponResult.getInfo());
        }
    }
}
